#include "Spell.h"

Spell::Spell(void)
{
}

Spell::~Spell(void)
{
}
void Spell::Update(float delta_time)
{
	core::vector3df pos = PartSyst->getPosition();
	if(
		(position.X!=pos.X) &&
		(position.Y!=pos.Y) &&
		(position.Z!=pos.Z) &&
		(lifeTime<790))
			onCollide();

	position.X += delta_time * speed.X * sin((float)(rotation.Y+90)*PI/180.0f) * cos(rotation.X*PI/180.0f);
	position.Z += delta_time * speed.X * cos((float)(rotation.Y+90)*PI/180.0f) * cos(rotation.X*PI/180.0f);
	position.Y -= delta_time * speed.Y * sin(rotation.X*PI/180.0f);
	PartSyst->setPosition(position);

	if(lifeTime<0)
	{
		isEnabled=false;
		PartSyst->setVisible(false);
	}
	else
		lifeTime--;

	if((dam.isEnabled)&&(dam.offset<-80))
		isEnabled=false;

}

void Spell::Destroy()
{

}

void Spell::onCollide(Entity* e)	
{
	isAlive = false;
	isVisible = false;
	PartSyst->setVisible(false);


	if(e->type == eType::eT_Player)
	{
		cout << "la comi" << endl;
	}

	if(e->type == eType::eT_Enemy)
	{
		dam.CreateDamage(e,sDamage);
		e->hp-=sDamage;
		cout << "comela! " << e->hp << " - " <<  sDamage << endl;
	}
}

void Spell::onCollide()	
{
	isEnabled = false;
	isAlive = false;
	isVisible = false;
	PartSyst->setVisible(false);
}
